﻿using System;
using System.Collections.Generic;
using System.Linq;
using InvestmentIntelligence.DbModel.Models;

namespace InvestmentIntelligence.Data.Repository.EFImplementation
{
    using System.Data.Entity;

    public class AnalyticsIdeaRepository : IIPRepository<AnalyticsIdea>, IAnalyticsIdeaRepository
    {
        public List<T> GetSlowList<T>(Func<IQueryable<AnalyticsIdea>, IEnumerable<T>> f)
        {
            return InternalGet(dc =>
            {
                dc.Database.CommandTimeout = 300;
                return dc.AnalyticsIdeas;

            }, queryable => f(queryable).ToList());
        }

        public List<CompassTradeToInvestment> GetInvestmentTradesByFundBook(int fundBookId)
        {
            return RunUnitOfWork(dc => (from investment in dc.Investments
                                        from t in investment.TradedQuantities
                                        where investment.FundBookEntityId == fundBookId && t.TradeId!=null
                                        select new CompassTradeToInvestment
                                        {
                                            InvestmentId = investment.Id,
                                            TradeId = t.TradeId.Value,                                            
                                        }).ToList());
        }


    }
}
